from RedisClient import RedisClient


class RedisPubSubHelper(object):

    def __init__(self, channel):
        self.client = RedisClient()
        self.channel = channel
        self.pubsub = None

    def subscribe(self):
        self.pubsub = self.client.get_redis().pubsub()
        self.pubsub.subscribe(self.channel)
        return self.pubsub

    def unsubscribe(self):
        return self.pubsub.unsubscribe(self.channel)

    def publish(self, msg):
        return self.client.get_redis().publish(self.channel, msg)
